/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */

package jdbcmanager.dbtools.datatypes;

/**
 * Defines type of data that can be applied to a column's table. 
 *  
 * @author Francisco Morero Peyrona
 */
public final class TableColumnTypeDefinition
{
   private String  sName          = "Unknown";
   private int     nType          = -1;          // from java.sql.Types
   private int     nPrecision     = -1;          // Max field size
   private boolean bNullabe       = false;       // Accepts null values?
   private boolean bCaseSensitive = false;
   private boolean bUnsigned      = false;
   private boolean bMoneyValue    = false;
   private boolean bAutoIncrement = false;       // Can be used as auto-increment?
   private String  sLocalName     = "Unknown";
   private int     nMinScale      = 0;           // Minimum number of digits after decimal separator
   private int     nMaxScale      = 0;           // Maximum number of digits after decimal separator
   private String  sLiteralPrefix = "";
   private String  sLiteralSufix  = "";
   
   //-------------------------------------------------------------------------//
   
   /** @return    */
   public String  getName()              { return this.sName;           }
   
   /** @return The SQL type as implemented in <code>java.sql.Types</code> */
   public int     getType()              { return this.nType;           }

   /** @return    */
   public int     getPrecision()         { return this.nPrecision;      }

   /** @return    */
   public boolean isNullabe()            { return this.bNullabe;        }

   /** @return    */
   public boolean isCaseSensitive()      { return this.bCaseSensitive;  }

   /** @return    */
   public boolean isUnisgned()           { return this.bUnsigned;       }

   /** @return    */
   public boolean isMoneyValue()         { return this.bMoneyValue;     }

   /** @return    */
   public boolean isAutoIncrementable()  { return this.bAutoIncrement;  }

   /** @return    */
   public String  getLocalName()         { return this.sLocalName;      }

   /** @return    */
   public int     getMinScale()          { return this.nMinScale;       }

   /** @return    */
   public int     getMaxScale()          { return this.nMaxScale;       }
   
   /**  @return   */
   public String  getLiteralPrefix()     { return this.sLiteralPrefix;  }

   /**  @return   */
   public String  getLiteralSufix()      { return this.sLiteralSufix;   }

   //-------------------------------------------------------------------------//
   
   /**
    * 
    * @param aoColType Array with all posible types
    * @param nSqlType Type number that returns the driver
    * @return matching type number
    */
   public static int searchOnType( TableColumnTypeDefinition[] aoColType, int nSqlType )
   {
      for( int n = 0; n < aoColType.length; n++ )
      {
         if( aoColType[n].getType() == nSqlType )
            return n;
      }
      // TODO: handle error message properly
      System.out.println( "column type not found: " + nSqlType);  // TODO: remove later. For testing purp.
      System.out.println( "Valid Types:");
      for (int i = 0; i < aoColType.length; i++)
      {
		    System.out.println( "aoColType["+i+"] " + aoColType[i]);
      }
      return -1;
   }
   
   /**
    * 
    * @param aoColType
    * @param sTypeName
    * @return
    */
   public static int searchOnName( TableColumnTypeDefinition[] aoColType, String sTypeName )
   {
      for( int n = 0; n < aoColType.length; n++ )
      {
         if( aoColType[n].getName().equals( sTypeName ) )
            return n;
      }
   
      return -1;
   }
   
   /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString()
    {
        return "sName: " + sName + " LocalName: " + sLocalName + " Type: " + nType;
    }
/**
 * @param autoIncrement The bAutoIncrement to set.
 */
public void setAutoIncrement(boolean autoIncrement)
{
    bAutoIncrement = autoIncrement;
}
/**
 * @param caseSensitive The bCaseSensitive to set.
 */
public void setCaseSensitive(boolean caseSensitive)
{
    bCaseSensitive = caseSensitive;
}
/**
 * @param moneyValue The bMoneyValue to set.
 */
public void setMoneyValue(boolean moneyValue)
{
    bMoneyValue = moneyValue;
}
/**
 * @param nullabe The bNullabe to set.
 */
public void setNullabe(boolean nullabe)
{
    bNullabe = nullabe;
}
/**
 * @param unsigned The bUnsigned to set.
 */
public void setUnsigned(boolean unsigned)
{
    bUnsigned = unsigned;
}
/**
 * @param maxScale The nMaxScale to set.
 */
public void setMaxScale(int maxScale)
{
    nMaxScale = maxScale;
}
/**
 * @param minScale The nMinScale to set.
 */
public void setMinScale(int minScale)
{
    nMinScale = minScale;
}
/**
 * @param precision The nPrecision to set.
 */
public void setPrecision(int precision)
{
    nPrecision = precision;
}
/**
 * @param type The nType to set.
 */
public void setType(int type)
{
    nType = type;
}
/**
 * @param literalPrefix The sLiteralPrefix to set.
 */
public void setLiteralPrefix(String literalPrefix)
{
    sLiteralPrefix = literalPrefix;
}
/**
 * @param literalSufix The sLiteralSufix to set.
 */
public void setLiteralSufix(String literalSufix)
{
    sLiteralSufix = literalSufix;
}
/**
 * @param localName The sLocalName to set.
 */
public void setLocalName(String localName)
{
    sLocalName = localName;
}
/**
 * @param name The sName to set.
 */
public void setName(String name)
{
    sName = name;
}
}